#version 130

in vec3 LightIntensity;
in vec3 Position;
in vec3 Normal;
in vec4 TexCoord;
in vec3 EyeDirection_cameraspace;
in vec3 Normal_cameraspace;
in vec3 LightDirection_cameraspace;

uniform sampler2D Tex1;

out vec4 FragColor;


void main() 
{
	vec2 coordUV = vec2(TexCoord.x, TexCoord.y);

	 // Material properties
    vec3 MaterialDiffuseColor = vec3(texture( Tex1, coordUV ));
    vec3 MaterialSpecularColor = vec3(1.0,1.0,1.0);
 
 
    vec3 n = normalize( Normal_cameraspace );
   
    vec3 l = normalize( LightDirection_cameraspace );

    float cosTheta = clamp( dot( n,l ), 0,1 );

    vec3 E = normalize(EyeDirection_cameraspace);
    
    vec3 R = reflect(l,n);

    float cosAlpha = clamp( dot( E,R ), 0,1 );



	gl_FragColor  = vec4 (vec3(0.2,0.2,0.2)+ MaterialDiffuseColor  * LightIntensity + 
							MaterialSpecularColor * LightIntensity * cosAlpha, 0.8);
}